package com.hd.rabbit.producer;

import com.hd.rabbit.producer.MqProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * MQ服务者
 */
@Component
public class MqProducerImpl implements MqProducer {
    private final static Logger logger = LoggerFactory.getLogger(MqProducerImpl.class);

    @Resource
    private AmqpTemplate amqpTemplate;
    @Override
    public void sendDataToQueue(String queueKey, Object object) {
        try{
            //加入队列
            amqpTemplate.convertAndSend(queueKey, object);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
    }
}
